package cn.tedu.yl.role.controller;

import cn.tedu.yl.base.response.JsonResult;
import cn.tedu.yl.base.response.PageData;
import cn.tedu.yl.role.pojo.dto.RoleDelParam;
import cn.tedu.yl.role.pojo.dto.RoleListQuery;
import cn.tedu.yl.role.pojo.dto.RoleSaveParam;
import cn.tedu.yl.role.pojo.vo.RoleVO;
import cn.tedu.yl.role.service.roleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "角色管理模块")
@RestController
@RequestMapping("v1/role")
public class roleController {
    @Autowired
   private roleService roleService;


    @ApiOperation(value = "查询角色列表")
    @GetMapping("list")
    public JsonResult list(RoleListQuery roleListQuery){
        PageData pageData = roleService.selectList(roleListQuery);
        return JsonResult.ok(pageData);
    }

    @ApiOperation(value = "编辑角色")
    @PostMapping("save")
    public JsonResult save(@Validated @RequestBody RoleSaveParam roleSaveParam){
        roleService.save(roleSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation(value = "删除角色")
    @PostMapping("delete")
    public JsonResult delete(@RequestBody RoleDelParam roleDelParam){
        roleService.delete(roleDelParam);
        return JsonResult.ok();
    }

    @ApiOperation(value = "查询角色详情")
    @GetMapping("detail/{id}")
    public JsonResult selectDetailById(@PathVariable("id") Integer id){
        RoleVO roleVO = roleService.selectDetailById(id);
        return JsonResult.ok(roleVO);
    }


}































